package com.meida.boot.handler.app;


import com.meida.common.mybatis.entity.EntityMap;
import com.meida.common.mybatis.interceptor.IndexInterceptor;
import com.meida.common.mybatis.query.CriteriaQuery;
import com.meida.module.product.client.entity.ProdShop;
import com.meida.module.product.provider.service.ProdProductService;
import com.meida.module.product.provider.service.ProdShopService;
import com.meida.module.system.provider.service.SysSliderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * APP首页接口
 *
 * @author zyf
 */
@Component("appIndexHandler")
public class AppIndexHandler implements IndexInterceptor {

    @Autowired
    private SysSliderService sliderService;
    @Autowired
    private ProdProductService prodProductService;

    @Autowired
    private ProdShopService prodShopService;


    @Override
    public EntityMap complete(EntityMap params) {
        EntityMap result = new EntityMap();
        //轮播图
        List<EntityMap> sliderList = sliderService.listBySliderType(1, 5);

        //弹窗 广告
        EntityMap alertSlider=sliderService.getBySliderType(200);
        result.put("alertSlider", alertSlider);
        result.put("sliderList", sliderList);
        //精选商品
        List<EntityMap> productList = prodProductService.listRecommend(4, false);
        productList.stream().forEach(product -> {
            product.put("feedbackRate", "98%");
        });
        result.put("productList", productList);
        //附近商家
        List<EntityMap> shopList = prodShopService.listNearby(params, 10, false);

        CriteriaQuery cq = new CriteriaQuery(ProdShop.class);
        List<EntityMap> shopRecommendList = prodShopService.listRecommend(cq, 10, false);

        result.put("shopList", shopList);
        result.put("shopRecommendList", shopRecommendList);
        return result;
    }
}
